<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<jsp:include page="../inc.jsp" /> 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="${ctx}/js/kindedit/themes/default/default.css" />
		<link rel="stylesheet" href="${ctx}/js/kindedit/plugins/code/prettify.css" />
		<script type="text/javascript" src="${ctx }/js/kindedit/kindeditor-all.js" ></script>
		<script type="text/javascript" src="${ctx }/js/kindedit/lang/zh-CN.js" ></script>
		<script type="text/javascript" src="${ctx }/js/kindedit/plugins/code/prettify.js" ></script>
	</head>
	<body>
		<style type="text/css">
			table#formTb tr{
				height: 30px;
				border-bottom: 1px solid #d4d4d4;
				margin: 5px;
			}	
			table#formTb tr td{
				padding: 5px 3px;
			}
		</style>
		<script type="text/javascript">
				    var dg,editor;
				    KindEditor.ready(function(K) {
						 editor= K.create('textarea[id="center"]', {
							cssPath : '${ctx }/js/kindedit/plugins/code/prettify.css',
							uploadJson : '${ctx }/js/kindedit/jsp/upload_json.jsp',
							fileManagerJson : '${ctx }/js/kindedit/jsp/file_manager_json.jsp',
							allowFileManager : true,
							afterCreate : function() {
								var self = this;
								K.ctrl(document, 13, function() {
									self.sync();
									document.forms['example'].submit();
								});
								K.ctrl(self.edit.doc, 13, function() {
									self.sync();
									document.forms['example'].submit();
								});
							}
						});
						prettyPrint();
					});
					$(function(){
						
						
						
						
						
						
						dg = $('#table').datagrid({
							url:'${ctx}/tc/find.coc',
							fit:true,
							singleSelect:true,
							rownumbers:true,
							pagination:true,
							columns:[[
								{field:'ck',checkbox:true,width:50},
								{field:'title',title:'标题',width:150,fixed:true},
								{field:'author',title:'作者',width:150,fixed:true},
								{field:'showDate',title:'发布时间',width:100,fixed:true},
								{field:'center',title:'思想内容',width:300,fixed:true,
									formatter:function(v,r,i){
										return "此处省略...,注意:<font style='color:red'>点击右侧'查看',预览内容</font>";
									}
								
								},
								
								{field:'at',title:'操作',width:100,fixed:true,align:'center',
									formatter:function(v,r,i){
										v = '';
										v += '<a onclick="checkData('+i+')" href="#" style="color:blue;text-decoration:none">查看<a/>';
										v += '&nbsp;|&nbsp;';
										v += '<a onclick="delData('+i+')" href="#" style="color:red;text-decoration:none">删除<a/>';
										return v;
									},
									styler:function(v,r,i){
										return 'background-color:#d4d4d4'
									}
								}
							]],
							onLoadSuccess:function(data){
								$('#ns').html(data.total);
							}
						});
						//dg.datagrid('loadData',json);
						//刷新分页
						//setTimeout(function(){dg.datagrid({loadFilter:pagerFilter}).datagrid('loadData')},10);
						
						$('#btn1').click(function(){
							
							var f = $('#dataForm');
							
							if(f.form('validate')){
								

								var sd = $('#showDate').datebox('getValue');
							
								var ed = $('#author').textbox('getValue');
								
								var title = $('#title').textbox('getValue');
								//获取富文本内容
								var center = editor.html();
								
								$("#ct").val(center);
								
								
								//进度条
								progressLoad();
								 //$.ajax({ 
								var option ={	
									type:'post',
									url:'${ctx}/tc/insert.coc',
								   
									dataType:'json',
									success:function(r){
										$.messager.alert('系统提示',r.msg,'info');
										if(r.is){
											//关闭进度条
											progressClose();
											//清空表单内容
											cleanForm();
											$('#table').datagrid('reload');//刷新数据表格
											('#ns').html(r.obj);
											
										}
										progressClose();
										//关闭进度条
										
									}
								 }; 
								// }); 
								//表单提交
								f.ajaxSubmit(option);
								
							}
						});
						
						
					});
					
					
					function delData(index){
						dg.datagrid('selectRow',index);
						var row = dg.datagrid('getSelected');
						var msg = '<p style="font-size:18px;color:red;font-weight:bold;">是否真的删除记录?</p>';
						
						$.messager.confirm('系统警告',msg,function(r){
							if(r){
								var id = row.id;
								$.ajax({
									type:'post',
									url:'${ctx}/tc/remove/'+id+'.coc',
									dataType:'json',
									success:function(r){
										alert(r.msg);
										if(r.is){
											$('#table').datagrid('reload');//刷新数据表格
										}
									}
									
								});
							}
						})
						
					}
					
					
					function cleanForm(){
						
						$('#showDate').datebox('setValue','');
						$('#author').textbox('setValue','');
						$('#title').textbox('setValue','');
						editor.html('');
						
					}
					
					function checkData(index){
						
					   /*  var rows = dg.datagrid('getData');
					    rows = JSON.stringify(rows); */
					    
					    parent.$.modalDialog({
					    	width:1000,
					    	height:820,
					    	modal:true,
					    	closeble:true,
					    	title:'预览思想',
					    	href:'${ctx}/tc/shownotices.coc?index='+index
					    			
					    			
					    });
						
					}
					
					
					
					
					
					
					
					
					function getDateFromParam(str){
						var d = new Date();
						str = str.split("-");
						y = parseInt(str[0]);
						m = parseInt(str[1]);
						day = parseInt(str[2]);
						d.setFullYear(y,m,day);
						
						return d;
						
					}
					
					function addFiles(){
						var str = '<span style="float:left,margin-left:20px">'+
						'<input type="file" name="files" >'+
						'&nbsp;&nbsp;'+
						'<a onclick="removeFile(this)" style="color:red" href="#">移除</a>'+
						'</span>';
						
						$('#fs').append(str);
						
					}
					
					
					function removeFile(obj){
						
						var span = $(obj).parents('span');
						$(span).remove();
						
					}
					
					
					
				</script>
				<div id="tt" class="easyui-tabs" data-options="fit:true,tabPosition:'left'">   
				    <div data-options="iconCls:'icon-eadd'" title="新增思想汇报" 
				    	style="padding:20px 20px 5px 20px;display:none;">   
				        <div id="cc03" class="easyui-layout" fit=true>   
						    <div data-options="region:'center',border:false" style="padding:5px;background:#fff;">
						    	<form id="dataForm" enctype="application/x-www-form-urlencoded">
									<table id="formTb" width="100%">
										<tr>
											<td width="80px" align="right">标题:</td>
											<td>
												<input type="hidden" name="center" id="ct">
												<input  class="easyui-textbox" id = "title" name="title" data-options="width:300,required:true">
											</td>
										</tr>
										<tr>
											<td width="80px" align="right">作者:</td>
											<td>
												
												<input  class="easyui-textbox" id = "author" name="author" data-options="width:300,required:true">
											</td>
										</tr>
										<tr>
											<td align="right">发布时间:</td>
											<td>
												<input class="easyui-datebox" name="showDate" id="showDate" required=true editable=false>
											</td>
										</tr>
										
										<tr>
											<td align="right">思想内容:</td>
											<td>
												<textarea id="center" cols="100" rows="8" 
												style="width:700px;height:300px;visibility:hidden;">
												</textarea>
											</td>
										</tr>
										
									</table>
								</form>   
						    	
						    </div>
						    <div data-options="region:'south',border:false" style="height:30px;text-align: center;background:#fff
							padding-top: 10px;">
						    	<a id="btn1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定发布</a>
						    	<a id="btn2" onclick="cleanForm()" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">清除内容</a>
						    </div>   
						</div> 
					
				    </div>   
				    <div title="思想列表01    	<font style='color:#fff;background:red;border-radius: 3px;margin-top: 0px;' id='ns'>123</font>" data-options="closable:false,iconCls:'icon-more'" 
				    	style="overflow:auto;padding:20px;display:none;">   
						<div id="cc04" class="easyui-layout" fit=true>   
						    <div data-options="region:'north'" style="height:50px;">
						    	<div style="height: 30px;padding:10px 0px 5px 10px;min-width: 600px;">
						    		<form id="searchForm">
						    			<table class="searchTb">
						    				<tr>
						    					<td>
						    						条件1:
						    						<input class="easyui-textbox" name="" 
						    							style="border-radius: 0px;width:150px" />
						    						条件2:
						    						<input class="easyui-textbox" name="" 
						    							style="border-radius: 0px; width:150px"/>
						    					</td>
						    					<td>
						    						<a class="easyui-linkbutton" iconCls="icon-search" 
						    							style="border-radius: 3px;">查询一下</a>
						    					</td>
						    				</tr>
						    			</table>
						    		</form>
						    	</div>
						    </div>   
						    <div data-options="region:'center',title:'&nbsp;',iconCls:'icon-more',border:false" 
						    	style="padding:0px;background:#eee;">
						    	<table id="table"></table>
						    </div>   
						</div> 		    	
				    </div>     
				</div>
			</body>
		</html>

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
</body>
</html>